<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="创建人" prop="createTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择创建人">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="本次收费金额" prop="fee">
        <el-input
          v-model="queryParams.fee"
          placeholder="请输入本次收费金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收费时间" prop="feetime">
        <el-date-picker clearable size="small"
          v-model="queryParams.feetime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择收费时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="修改时间" prop="updateTime">
        <el-date-picker clearable size="small"
          v-model="queryParams.updateTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择修改时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="合同id" prop="contarctid">
        <el-input
          v-model="queryParams.contarctid"
          placeholder="请输入合同id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="项id" prop="incomeId">
        <el-input
          v-model="queryParams.incomeId"
          placeholder="请输入项id"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="计划周期信息" prop="contarctPlandate">
        <el-input
          v-model="queryParams.contarctPlandate"
          placeholder="请输入计划周期信息"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收费前已收金额" prop="prefee">
        <el-input
          v-model="queryParams.prefee"
          placeholder="请输入收费前已收金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="收费后已收金额" prop="lastFee">
        <el-input
          v-model="queryParams.lastFee"
          placeholder="请输入收费后已收金额"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="1收入2支出" prop="flowtype">
        <el-select v-model="queryParams.flowtype" placeholder="请选择1收入2支出" clearable size="small">
          <el-option
            v-for="dict in dict.type.flowtype"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="费用类型 1代表固定收费 2代表变化收费" prop="feetype">
        <el-select v-model="queryParams.feetype" placeholder="请选择费用类型 1代表固定收费 2代表变化收费" clearable size="small">
          <el-option
            v-for="dict in dict.type.feetype"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="固定收费 1代表租金 2代表管理费，变化收费对应费用表信息" prop="feetypeid">
        <el-select v-model="queryParams.feetypeid" placeholder="请选择固定收费 1代表租金 2代表管理费，变化收费对应费用表信息" clearable size="small">
          <el-option
            v-for="dict in dict.type.feetypeid"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['incomerecord:incomerecord:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['incomerecord:incomerecord:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['incomerecord:incomerecord:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['incomerecord:incomerecord:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="incomerecordList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" prop="id" />
      <el-table-column label="创建人" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="本次收费金额" align="center" prop="fee" />
      <el-table-column label="收费时间" align="center" prop="feetime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.feetime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="修改时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="合同id" align="center" prop="contarctid" />
      <el-table-column label="项id" align="center" prop="incomeId" />
      <el-table-column label="计划周期信息" align="center" prop="contarctPlandate" />
      <el-table-column label="收费前已收金额" align="center" prop="prefee" />
      <el-table-column label="收费后已收金额" align="center" prop="lastFee" />
      <el-table-column label="1收入2支出" align="center" prop="flowtype">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.flowtype" :value="scope.row.flowtype"/>
        </template>
      </el-table-column>
      <el-table-column label="费用类型 1代表固定收费 2代表变化收费" align="center" prop="feetype">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.feetype" :value="scope.row.feetype"/>
        </template>
      </el-table-column>
      <el-table-column label="固定收费 1代表租金 2代表管理费，变化收费对应费用表信息" align="center" prop="feetypeid">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.feetypeid" :value="scope.row.feetypeid"/>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['incomerecord:incomerecord:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['incomerecord:incomerecord:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改收费记录对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="创建人" prop="createTime">
          <el-date-picker clearable size="small"
            v-model="form.createTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择创建人">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="本次收费金额" prop="fee">
          <el-input v-model="form.fee" placeholder="请输入本次收费金额" />
        </el-form-item>
        <el-form-item label="收费时间" prop="feetime">
          <el-date-picker clearable size="small"
            v-model="form.feetime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择收费时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="修改时间" prop="updateTime">
          <el-date-picker clearable size="small"
            v-model="form.updateTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择修改时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="合同id" prop="contarctid">
          <el-input v-model="form.contarctid" placeholder="请输入合同id" />
        </el-form-item>
        <el-form-item label="项id" prop="incomeId">
          <el-input v-model="form.incomeId" placeholder="请输入项id" />
        </el-form-item>
        <el-form-item label="计划周期信息" prop="contarctPlandate">
          <el-input v-model="form.contarctPlandate" placeholder="请输入计划周期信息" />
        </el-form-item>
        <el-form-item label="收费前已收金额" prop="prefee">
          <el-input v-model="form.prefee" placeholder="请输入收费前已收金额" />
        </el-form-item>
        <el-form-item label="收费后已收金额" prop="lastFee">
          <el-input v-model="form.lastFee" placeholder="请输入收费后已收金额" />
        </el-form-item>
        <el-form-item label="1收入2支出" prop="flowtype">
          <el-select v-model="form.flowtype" placeholder="请选择1收入2支出">
            <el-option
              v-for="dict in dict.type.flowtype"
              :key="dict.value"
              :label="dict.label"
:value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="费用类型 1代表固定收费 2代表变化收费" prop="feetype">
          <el-select v-model="form.feetype" placeholder="请选择费用类型 1代表固定收费 2代表变化收费">
            <el-option
              v-for="dict in dict.type.feetype"
              :key="dict.value"
              :label="dict.label"
:value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="固定收费 1代表租金 2代表管理费，变化收费对应费用表信息" prop="feetypeid">
          <el-select v-model="form.feetypeid" placeholder="请选择固定收费 1代表租金 2代表管理费，变化收费对应费用表信息">
            <el-option
              v-for="dict in dict.type.feetypeid"
              :key="dict.value"
              :label="dict.label"
:value="parseInt(dict.value)"
            ></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listIncomerecord, getIncomerecord, delIncomerecord, addIncomerecord, updateIncomerecord } from "@/api/incomerecord/incomerecord";

export default {
  name: "Incomerecord",
  dicts: ['feetype', 'feetypeid', 'flowtype'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 收费记录表格数据
      incomerecordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        createTime: null,
        fee: null,
        feetime: null,
        updateTime: null,
        contarctid: null,
        incomeId: null,
        contarctPlandate: null,
        prefee: null,
        lastFee: null,
        flowtype: null,
        feetype: null,
        feetypeid: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询收费记录列表 */
    getList() {
      this.loading = true;
      listIncomerecord(this.queryParams).then(response => {
        this.incomerecordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createTime: null,
        fee: null,
        feetime: null,
        updateTime: null,
        contarctid: null,
        createBy: null,
        incomeId: null,
        updateBy: null,
        contarctPlandate: null,
        prefee: null,
        lastFee: null,
        flowtype: null,
        feetype: null,
        feetypeid: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加收费记录";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getIncomerecord(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改收费记录";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateIncomerecord(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addIncomerecord(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除收费记录编号为"' + ids + '"的数据项？').then(function() {
        return delIncomerecord(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('incomerecord/incomerecord/export', {
        ...this.queryParams
      }, `incomerecord_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
